package cn.ms.doctor.Service;

import cn.ms.doctor.Entity.Patient;
import cn.ms.doctor.Mapper.PatientMapper;
import cn.ms.doctor.Mapper.PrescriptionMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PatientServiceImpl implements PatientService{

    @Resource
    PatientMapper patientMapper;
    @Resource
    PrescriptionMapper prescriptionMapper;

    @Override
    public Map<String, Object> getPatientBySearch(Map<String, Object> params) {
        Map<String, Object> data=new HashMap<>();
        Page<Object> objects = PageHelper.startPage((Integer) params.get("pageIndex"), (Integer) params.get("pageSize"));
        List<Patient> patientDatas=patientMapper.getPatientBySearch(params);
        data.put("pageData",patientDatas);
        data.put("pageIndex",objects.getPageNum());
        data.put("pageSize",objects.getPageSize());
        data.put("pageCount",objects.getPages());
        return data;
    }

    @Override
    public boolean updatePatientNameOrIdnumOrSex(Patient patient) {
        return patientMapper.updatePatientNameOrIdnumOrSex(patient);
    }

    @Override
    public boolean addPatient(Patient patient) {

        return patientMapper.addPatient(patient);
    }

    @Override
    public Integer getPatientCountByIdnum(String patientIdnum) {
        return patientMapper.getPatientCountByIdnum(patientIdnum);
    }

    @Override
    public boolean deletePatientByIdAndIdnum(Patient patient) {
        return patientMapper.deletePatientByIdAndIdnum(patient);
    }
}
